import { renderSalePriceInput, getActualAddRate } from '@/utils/salePrice';
import InputNumber from '@/components/inputNumber/inputNumber'

// 准入相关售价页面表列
export const ADD_TABLE_COLUMNS = [
  {
    title: 'SKU编码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '规格',
    key: 'spec'
  },
  {
    title: '是否畅销',
    key: 'sellWellFlagStr'
  },
  {
    title: '省',
    key: 'provinceName'
  },
  {
    title: '城市',
    key: 'cityName'
  },
  {
    title: '计量单位',
    key: 'unit'
  },
  {
    title: '品牌',
    key: 'brandName'
  },
  {
    title: '系列',
    key: 'series'
  },
  {
    title: '售价指导加价率',
    key: 'guideAddRate',
    width: 130
  },
  {
    title: '标准加价率',
    key: 'standardAddRate'
  },
  {
    title: '标准加价率来源',
    key: 'addRateTypeStr',
    width: 130
  },
  {
    title: '成本价',
    key: 'costPrice'
  },
  {
    title: '售价',
    width: 160,
    render: (h, { row }) => renderSalePriceInput(h, row)
  },
  {
    title: '售价实际加价率', // 前端自定义字段，根据公式计算所得，仅展示，不入库
    width: 130,
    render: (h, { row }) => <span>{getActualAddRate(row)}</span>
  },
  {
    title: '销售面价',
    width: 160,
    render: (h, { row }) => renderInputNumber(h, row, 'facePrice')
  },
  {
    title: '限制展示价',
    width: 160,
    render: (h, { row }) => renderInputNumber(h, row, 'limitShowPrice')
  },
  {
    title: '限制交易价',
    width: 160,
    render: (h, { row }) => renderInputNumber(h, row, 'limitTradePrice')
  },
]

// 准入相关售价查看单据表列
export const VIEW_RECORD_TABLE_COLUMNS = [
  {
    title: 'SKU编码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '规格',
    key: 'spec'
  },
  {
    title: '是否畅销',
    key: 'sellWellFlagStr'
  },
  {
    title: '省',
    key: 'provinceName'
  },
  {
    title: '城市',
    key: 'cityName'
  },
  {
    title: '计量单位',
    key: 'unit'
  },
  {
    title: '品牌',
    key: 'brandName'
  },
  {
    title: '系列',
    key: 'series'
  },
  {
    title: '标准加价率',
    key: 'standardAddRate'
  },
  {
    title: '成本价',
    key: 'costPrice'
  },
  {
    title: '售价',
    key: 'salePrice'
  },
  {
    title: '售价实际加价率', // 前端自定义字段，根据公式计算所得，仅展示，不入库
    width: 130,
    render: (h, { row }) => <span>{getActualAddRate(row)}</span>
  },
  {
    title: '销售面价',
    key: 'facePrice'
  },
  {
    title: '限制展示价',
    key: 'limitShowPrice'
  },
  {
    title: '限制交易价',
    key: 'limitTradePrice'
  }
]

// 渲染数值输入框
export const renderInputNumber = (h, row, prop, attrs) => <InputNumber
  value={row[prop]}
  precision={attrs?.precision ?? 2}
  min={attrs?.min ?? 0}
  size="mini"
  controls={false}
  onInput={val => { row[prop] = val }}
/>
